1213B - Bad Prices - CodeForces Solution


data structures implementation *1100

Please click on ads to support us..

Python Code:

def bad_price():
    t=int(input())    for i in range(t):
        n=int(input())        a=list(map(int,input().split()))        minimum=a[n-1]   
        counter=0
        for s in range(n-2,-1,-1):
            if a[s]> minimum:                counter+=1
            minimum = min([a[s] ,minimum])
        print(counter)
    
bad_price()

C++ Code:

#include <stdio.h>

int main() {
    int t,n,a[150005],min;
    scanf("%d",&t);
    while(t--)
    {
        int flag=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        min = a[n];
        for(int i=n;i>=1;i--)
        {
            if(a[i]<=min)
            {
                min=a[i];
            }
            else flag++;
        }
        printf("%d\n",flag);
    }
    return 0;
}
     				  		 		 	 	 		 				  	


Comments

Submit
0 Comments
More Questions

802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar
934A - A Compatible Pair
1618F - Reverse
1684C - Column Swapping
57C - Array